<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="/static/jQuery-1.11/jquery-1.11.3.min.js"></script>
    <script>
        $(function () {
            // 检查用户名
            $("#username").blur(function () {
                var username = $(this).val();
                var param = "username=" + username;
                $.get('/user/checkName',param,function (data) {
                    if (data.success) {
                        $("#p").html(data.msg).css('color','green');
                        $("#button").attr('disabled', false);
                    }else {
                        $("#p").html(data.msg).css('color','red');
                        $("#button").attr('disabled', true);
                    }
                })
            });

            // 注册
            $("#button").click(function () {
                var username = $("#username").val();
                var password = $("#password").val();
                var param = "username=" + username + "&password=" + password;
                $.post("/user/register", param, function (data) {
                    if (!data.success) {
                        $("#p2").html(data.msg).css('color','red');
                    }else {
                        location.href = 'login2.html';
                    }
                })
            })

        });
    </script>
</head>
<body>
<h4>注册</h4>

    用户名：<input type="text" name="username" id="username"><span id="p"></span><br/>
    密码：<input type="password" name="password" id="password"><span id="p2"></span><br/>
    <input id="button" type="button" value="注册"/>


</body>
</html>